package com.changcheng.project.applist.controller;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.changcheng.common.TextUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import com.changcheng.framework.aspectj.lang.annotation.Log;
import com.changcheng.framework.aspectj.lang.enums.BusinessType;
import com.changcheng.project.applist.domain.AAppfileList;
import com.changcheng.project.applist.service.IAAppfileListService;
import com.changcheng.framework.web.controller.BaseController;
import com.changcheng.framework.web.domain.AjaxResult;
import com.changcheng.common.utils.poi.ExcelUtil;
import com.changcheng.framework.web.page.TableDataInfo;

/**
 * APP文件列表Controller
 *
 * @author dazhi
 * @date 2020-10-30
 */
@Controller
@RequestMapping("/app/applist")
public class AAppfileListController extends BaseController {
    private String prefix = "app/applist";

    @Autowired
    private IAAppfileListService aAppfileListService;

    @RequiresPermissions("app:applist:view")
    @GetMapping()
    public String applist() {
        return prefix + "/applist";
    }

    /**
     * 查询APP文件列表列表
     */
    @RequiresPermissions("app:applist:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AAppfileList aAppfileList) {
        startPage();
        List<AAppfileList> list = aAppfileListService.selectAAppfileListList(aAppfileList);
        return getDataTable(list);
    }

    /**
     * 导出APP文件列表列表
     */
    @RequiresPermissions("app:applist:export")
    @Log(title = "APP文件列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AAppfileList aAppfileList) {
        List<AAppfileList> list = aAppfileListService.selectAAppfileListList(aAppfileList);
        ExcelUtil<AAppfileList> util = new ExcelUtil<AAppfileList>(AAppfileList.class);
        return util.exportExcel(list, "applist");
    }

    /**
     * 新增APP文件列表
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    int zhi = 0;

    /**
     * 新增保存APP文件列表
     */
    @RequiresPermissions("app:applist:add")
    @Log(title = "APP文件列表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AAppfileList aAppfileList) {


        if (!TextUtils.isBlank(aAppfileList.getFileAddress()) &&
                !TextUtils.isBlank(aAppfileList.getFileName()) &&
                !TextUtils.isBlank(aAppfileList.getFileVersion()) &&
                !TextUtils.isBlank(aAppfileList.getTime())

        ) {
            zhi = aAppfileListService.insertAAppfileList(aAppfileList);
            return toAjax(zhi);
        } else {
            zhi = -1;
            return toAjax2(zhi, "数据不能为空！");
        }


    }

    /**
     * 修改APP文件列表
     */
    @GetMapping("/edit/{id}")

    public String edit(@PathVariable("id") Long id, ModelMap mmap) {

        AAppfileList aAppfileList = aAppfileListService.selectAAppfileListById(id);
//        initBinder(binder);
        mmap.put("aAppfileList", aAppfileList);
        return prefix + "/edit";
    }


    /**
     * 修改保存APP文件列表
     */
    @RequiresPermissions("app:applist:edit")
    @Log(title = "APP文件列表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AAppfileList aAppfileList) {

        if (!TextUtils.isBlank(aAppfileList.getFileAddress()) &&
                !TextUtils.isBlank(aAppfileList.getFileName()) &&
                !TextUtils.isBlank(aAppfileList.getFileVersion()) &&
                !TextUtils.isBlank(aAppfileList.getTime())

        ) {
            zhi = aAppfileListService.updateAAppfileList(aAppfileList);
            return toAjax(zhi);
        } else {
            zhi = -1;
            return toAjax2(zhi, "数据不能为空！");
        }
    }

    /**
     * 删除APP文件列表
     */
    @RequiresPermissions("app:applist:remove")
    @Log(title = "APP文件列表", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(aAppfileListService.deleteAAppfileListByIds(ids));
    }
}
